import load

def newChannel():
    return [[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]

def get13_16Avg(group):
    allChannel=[]
    for _ in range(40): # 从1到39，为了下标对应，0不要了
        allChannel.append(newChannel())

    startSub=load.getT1StartSub(group)

    for i in range(195):
        comNum=int(load.getCellT1(i,startSub+load.comNum))
        year=int(load.getCellT1(i,startSub+load.year))
        if year!=2017: # 只计算13到16
            for d in range(8):
                sum,num=allChannel[comNum][d]
                tableD = d + load.d1
                sum+=float(load.getCellT1(i,startSub+tableD))
                num+=1
                allChannel[comNum][d]=[sum,num]

    for comNum in range(1,40):
        for d in range(8):
            sum,num=allChannel[comNum][d]
            allChannel[comNum][d]=sum/num

    return allChannel

def strChannel(channel):
    result=''
    for d in channel:
        result+=str(d)+','
    return result

def strAllChannel(allChannel):
    result=''
    for i in range(1,40):
        line=str(i)+','+strChannel(allChannel[i])
        result+=line+'\n'
    return result

if __name__=='__main__':
    for g in range(1,7):
        allChannel=get13_16Avg(g)
        print(strAllChannel(allChannel))


